import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.HashSet;
import java.util.LinkedHashSet;

public class ArrowControl implements KeyListener {
	private Player				player;
	private HashSet<Integer>	keyPressed;

	public ArrowControl( Player player ) {
		this.player = player;
		keyPressed = new LinkedHashSet<Integer>();
	}

	public void performActions() {
		for( int key : keyPressed ) {
			perform( key );
		}
	}

	@Override
	public void keyPressed( KeyEvent ke ) {
		keyPressed.add( ke.getKeyCode() );
	}

	@Override
	public void keyReleased( KeyEvent ke ) {
		keyPressed.remove( ke.getKeyCode() );
	}

	@Override
	public void keyTyped( KeyEvent ke ) {
		perform( ke.getKeyCode() );
	}

	private void perform( int key ) {
		switch( key ) {
		case KeyEvent.VK_UP:
			player.moveForward();
			break;
		case KeyEvent.VK_LEFT:
			player.turnLeft( 10 ); // TODO graden bepalen uit andere controller
			break;
		case KeyEvent.VK_RIGHT:
			player.turnRight( 10 ); // TODO graden bepalen uit andere controller
			break;
		case KeyEvent.VK_DOWN:
			player.moveBackward();
			break;
		case KeyEvent.VK_SPACE:
			player.shoot();
			break;
		}
		System.out.println( player.getPosition() + ">" + player.getDirection() );
	}
}
